package reflect;

import java.io.File;
import java.lang.reflect.Method;

public class Test3 {
    public static void main(String[] args) throws Exception {


        File dir = new File(
                Test3.class.getResource(".").toURI()

        );
        String packageName = Test3.class.getPackage().getName();
        System.out.println(packageName);

        File[] className = dir.listFiles(f->f.getName().endsWith(".class"));
        for (File file : className) {

            String fileName = file.getName();
            System.out.println(fileName);
            String substring = fileName.substring(0, fileName.indexOf("."));
            System.out.println(substring);
            Class<?> cls = Class.forName(packageName + "." + substring);
            Object obj = cls.newInstance();

            Method[] methods = cls.getDeclaredMethods();
            for (Method method : methods) {

                if (method.getName().contains("s")
                        &&
                        method.getParameterCount() == 0) {

                    method.setAccessible(true);
                    method.invoke(obj);
                    method.setAccessible(false);



                }


            }

        }


    }
}
